<template>
  <!-- 中间部分图表 -->
  <el-card class="box-card" style="margin:10px 0px">
    <div slot="header" class="clearfix">
      <!-- v-model="activeName" @tab-click="handleClick" -->
      <!-- 头部左侧 -->
      <el-tabs v-model="activeName" class="tab">
        <el-tab-pane label="销售额" name="1" />
        <el-tab-pane label="访问量" name="2" />
      </el-tabs>
      <!-- 头部右侧内容 -->
      <div class="right">
        <span @click="setDay">今日</span>
        <span @click="setWeek">本周</span>
        <span @click="setMonth">本月</span>
        <span @click="setYear">本年</span>
        <!-- v-model="value1" -->
        <el-date-picker
          v-model="date"
          class="date"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          size="mini"
          value-format="yyyy-MM-dd"
        />
      </div></div>
    <div>
      <el-row :gutter="10">
        <el-col :span="18">
          <!-- 容器 -->
          <div ref="charts" class="charts" />
        </el-col>
        <el-col :span="6">
          <div class="right2">
            <h3>{{ title }}排行榜</h3>
            <ul>
              <li>
                <span class="index">1</span>
                <span>{{ Driver1 }}</span>
                <span class="rval">999</span>
              </li>
              <li>
                <span class="index">2</span>
                <span>{{ Driver2 }}</span>
                <span class="rval">128</span>
              </li>
              <li>
                <span class="index">3</span>
                <span>{{ Driver3 }}</span>
                <span class="rval">97</span>
              </li>
              <li>
                <span class="index2">4</span>
                <span>{{ Driver4 }}</span>
                <span class="rval">36</span>
              </li>
              <li>
                <span class="index2">5</span>
                <span>{{ Driver5 }}</span>
                <span class="rval">15</span>
              </li>
              <li>
                <span class="index2">6</span>
                <span>{{ Driver6 }}</span>
                <span class="rval">9</span>
              </li>
              <li>
                <span class="index2">7</span>
                <span>{{ Driver7 }}</span>
                <span class="rval">3</span>
              </li>
            </ul>
          </div>
        </el-col>
      </el-row>
    </div>
  </el-card>
</template>

<script>

import { theMonPrice, setName, lastmonth } from '@/api/activityCharge'

import echarts from 'echarts'
import dayjs from 'dayjs'
export default {
  name: '',
  data() {
    return {
      activeName: '1',
      myecharts: null,
      date: [], // 日期
      MonPrice: 0, // 月流水
      month:0, //上月流水
      monList: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // 月流水列表
      Driver1: [], // 司机1
      Driver2: [], // 司机2
      Driver3: [], // 司机3
      Driver4: [], // 司机4
      Driver5: [], // 司机5
      Driver6: [], // 司机6
      Driver7: [], // 司机7
    }
  },
  computed: {
    title() {
      return this.activeName === '1' ? '销售额' : '访问量'
    }
  },
  // 监听属性
  watch: {
    title() {
    // 从新修改图表配置数据
      this.myecharts.setOption({
        title: {
          text: this.title
        }
      })
    }
  },
  mounted() {
    this.theMonPrice() // 本月流水方法
    this.setName()
    this.lastmonth() // 上个月流水
  },
  methods: {
    // 今日
    setDay() {
      const day = dayjs().format('YYYY-MM-DD')
      this.date = [day, day]
    },
    // 本周
    setWeek() {
      const start = dayjs().day(1).format('YYYY-MM-DD')
      const end = dayjs().day(7).format('YYYY-MM-DD')
      this.date = [start, end]
    },
    // 本月
    setMonth() {
      const start = dayjs().startOf('month').format('YYYY-MM-DD')
      const end = dayjs().endOf('month').format('YYYY-MM-DD')
      this.date = [start, end]
    },
    // 本年
    setYear() {
      const start = dayjs().startOf('year').format('YYYY-MM-DD')
      const end = dayjs().endOf('year').format('YYYY-MM-DD')
      this.date = [start, end]
    },
    // 上个月流水
    lastmonth() {
      lastmonth().then(res=>{
        this.month = res.data[0].Months
        theMonPrice().then(res => {
        this.MonPrice = res.data[0].Months
        var newList = this.monList
        newList.splice(9, 0, this.MonPrice)
        newList.splice(9, 0, this.month)
        console.log(this.month)
        console.log(newList)
        console.log(this.MonPrice);
        // 初始化echarts实例
        this.myecharts = echarts.init(this.$refs.charts)
        this.myecharts.setOption({
          title: {
            text: this.title + '趋势'
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis: [
            {
              type: 'value'
            }
          ],
          series: [
            {
              name: 'Direct',
              type: 'bar',
              barWidth: '60%',
              data: newList,
              color: '#5171CB'
            }
          ]
        })
      })
      })
    },
    // 查询当月流水
    theMonPrice() {
      
    },
    // 查询 司机名
    async setName() {
      const res = await setName()
      if (res.code !== 200) return this.$message.error('获取失败')
      this.Driver1 = res.data[0].driverName
      this.Driver2 = res.data[1].driverName
      this.Driver3 = res.data[2].driverName
      this.Driver4 = res.data[3].driverName
      this.Driver5 = res.data[4].driverName
      this.Driver6 = res.data[5].driverName
      this.Driver7 = res.data[6].driverName
    }
  }
}
</script>
<style scoped>
.clearfix{
    position: relative;
    display: flex;
    justify-content: space-between;
}
.tab{
    width: 100%;
}
.right{
    position: absolute;
    right: 0px ;
}
.date{
    width: 220px;
    margin: 0px 20px;
}
.right span{
    margin: 0px 10px;
}
.charts{
    width: 100%;
    height: 300px;
}
.right2{
    margin-top: -20px;
}
ul{
    width: 100%;
    height: 300px;
    list-style: none;
    padding: 0px;
}
ul li{
    height: 11%;
}
ul span{
    margin: 0px 20px ;
}
.index{
    float: left;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: black;
    color: white;
    text-align: center;
}
.index2{
    float: left;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    color: black;
    text-align: center;
}
.rval{
    float: right;
}
</style>
